package com.zjw.socket.demo.starter.messageService.service.impl;

import com.zjw.socket.demo.starter.messageService.service.IConnectSession;
import com.zjw.socket.demo.starter.messageService.Message;
import com.zjw.socket.demo.starter.messageService.MessageParser;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetSocket;

public class VertxSocketConnectSession implements IConnectSession {

  private final NetSocket netSocket;

  private final Buffer buffer;

  public VertxSocketConnectSession(NetSocket netSocket, Buffer buffer) {
    this.netSocket = netSocket;
    this.buffer = buffer;
  }

  @Override
  public void writeMessage(Message message) {
    Buffer buffer1 = Buffer.buffer();
    buffer1.appendBytes(MessageParser.toByte(message));
    netSocket.write(buffer1);
  }

  @Override
  public void writeBytes(byte[] bytes) {
    Buffer buffer1 = Buffer.buffer();
    buffer1.appendBytes(bytes);
    netSocket.write(buffer1);
  }

  @Override
  public void disconnect() {
    netSocket.close();
  }


  @Override
  public void reconnect() {
    //pass
  }
}
